<%
    function getTdStyle(item) {
        if (item.will_sell) {
            return 'style="color: red"'; 
        } else if (item.will_buy) {
            return 'style="color: green"';
        } else {
            return '';
        }
    }

    function getTdTxt(item){
        if (item.will_sell) {
            return  '卖出'
        } else if (item.will_buy) {
            return  '买入'
        } else {
            return '--';
        }
    }

%>

<html>
    <head>
        <style>
        table {
            width: 400px;
            margin: 0 auto;
            border: 1px solid #000000;
            border-collapse: collapse;
        }
        
        th,
        td {
            border: 1px solid #000000;
            text-align: center;
        }
        
    </style>
    </head>
    <body>

        <h2>本次调仓日期:<%- currentDate %> </h2>
        <h3>上次调仓日期:<%- lastDate %> </h3>
        <table>
            <thead>
                <tr>
                    <th>序号</th>  
                    <th>股票名称</th>
                    <th>股票代码</th>
                    <th>股票价格</th>
                    <th>买入/卖出</th>
                  </tr>
            </thead>
            <tbody>
                <% for(let i=0; i < data.length; i++) { %>
                    <tr>
                      <td><%= data[i].sort %></td>
                      <td  <%- getTdStyle(data[i]) %>><%= data[i].stock_name %></td>
                      <td><%= data[i].stock_code %></td>  
                      <td><%= data[i].stock_price %></td>
                      <td  <%- getTdStyle(data[i]) %> >
                        <%-  getTdTxt(data[i]) %> 
                      </td>
                    </tr>
                  <% } %>
            </tbody>
          </table>


    </body>

</html>
